package com.xinya.wanandroidclient.ui.tab

import androidx.lifecycle.MutableLiveData
import com.xinya.wanandroidclient.Constants
import com.xinya.wanandroidclient.base.BaseRepository
import com.xinya.wanandroidclient.bean.ProjectClassificationBean
import com.xinya.wanandroidclient.http.RetrofitManager
import com.xinya.wanandroidclient.http.WanAndroidApiService
import kotlinx.coroutines.CoroutineScope

/**
 *
 * @ClassName:      TabRepo$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/3/2$ 15:49$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class TabRepo(viewModelScope: CoroutineScope) :
    BaseRepository(viewModelScope) {
    fun getTabList(type: Int,
                   tabLiveData: MutableLiveData<MutableList<ProjectClassificationBean>>) {
        launch(
            block = {
                when (type) {
                    Constants.WX_ACCOUNT_TYPE -> {
                        RetrofitManager.getApiService(WanAndroidApiService::class.java)
                            .getWXArticleChapters()
                            .result()
                    }
                    else -> {
                        RetrofitManager.getApiService(WanAndroidApiService::class.java)
                            .getProjectTree()
                            .result()
                    }
                }

            },
            success = {
                tabLiveData.postValue(it)
            }
        )
    }

}